import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';

class RecordConfigBean {
  List<ConfigBean> list;

  RecordConfigBean({this.list});

  RecordConfigBean.fromJson(Map<String, dynamic> json) {    
    this.list = (json['list'] as List)!=null?(json['list'] as List).map((i) => ConfigBean.fromJson(i)).toList():null;
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['list'] = this.list != null?this.list.map((i) => i.toJson()).toList():null;
    return data;
  }
}

class ConfigBean {
  String title;
  String type; // 单选、多选、填写、下拉
  String placeholder;
  String unit;
  String inputType; //单行文本、 单行数字、多行
  int isRequired; //是否是必须填写   1 必填 0 非必填
  int maxWords;
  List <dynamic> optionalAnswers;

  ConfigBean({this.title, this.type, this.placeholder, this.unit, this.inputType, this.isRequired, this.maxWords, this.optionalAnswers});

  ConfigBean.fromJson(Map<String, dynamic> json) {
    this.title = json['title'];
    this.type = json['type'];
    this.placeholder = json['placeholder'];
    this.unit = json['unit'];
    this.inputType = json['inputType'];
    this.isRequired = json['isRequired'];
    this.maxWords = json['maxWords'];
    this.optionalAnswers = new List<dynamic>();
    if(json['optionalAnswers']!= "") {
      if(objNotEmpty(json['optionalAnswers'] )) {
        List<dynamic> optionalAnswersList = json['optionalAnswers'];
        this.optionalAnswers.addAll (optionalAnswersList.map((o) => o.toString()));
      }
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['title'] = this.title;
    data['type'] = this.type;
    data['placeholder'] = this.placeholder;
    data['unit'] = this.unit;
    data['inputType'] = this.inputType;
    data['isRequired'] = this.isRequired;
    data['maxWords'] = this.maxWords;
    data['optionalAnswers'] = this.optionalAnswers;
    return data;
  }
}
